#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QMainWindow>
#include <qdatetime.h>
#include "FindFileSizes.h"
#include "Backup.h"

namespace Ui
{
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    /*
      Constructor - just sets up some basic stuff
      */
    MainWindow(QWidget *parent = 0);

    /*
      This just adds text to the textEdit at the bottom of the form.
      */
    void addToConsole(const QString &text);

    /*
      Adds a string to the backup list.
      If "isFile" is true, the entry will be colored.
      If it's false, the entry will have a '/' added to the end.
      */
    void addStringToList(const QString &text, bool isFile);

    /*
      This backs up just the main list of strings to a file.
      This should be called after every add/remove EXCEPT for when
      the list of things to be backed up is being populated from this file.
      */
    void backupListToFile();

    // finds the last time a file was modified
    static QDateTime fileLastModified(QString myFile);

    // checks to see if a path is a directory or a file
    // returns "true" if it's a directory, "false" if it's a file
    static bool isDirectory(QString path);

    // grabs the file name part of a path (e.g. "1/2/3/pic.bmp" turns into "pic.bmp")
    static QString onlyFileName(QString file);

    // Returns the items of "backupList" as a QStringList
    QStringList getBackupListItems();

    // Sets all of the buttons' "enabled" properties at once
    void setButtonsEnabled(bool enabled = true);

    // Takes an amount of bytes and converts it to an appropriate measurement (bytes, KB, MB, GB, or TB)
    QString bytesToString(qint64 bytes);

    ~MainWindow();

private:
    Ui::MainWindow *ui;

    // keeps track of the sum of all of the user's files that he or she wants to back up
    qint64 sumFileSizes;

    // Keeps track of the number of bytes copied in each backup call
    qint64 bytesCopied;

    // holds destination path
    QString backupPath;

    // Thread for finding file sizes
    FindFileSizes findFileSizes;

    // Thread for backing up
    Backup backup;


public slots:
    void receiveFileSizes(qint64 sum, uintmax_t freeSpace);
    void backupComplete(unsigned int numFoldersCopied, unsigned int numFilesCopied);
    void copiedBytes(qint64 bytes);
    void fileSizeProgress(int percent);

private slots:
    void on_stopButton_clicked();
    void on_backupLine_editingFinished();
    void on_backupButton_clicked();
    void on_addFilesButton_clicked();
    void on_addFolderButton_clicked();
    void on_removeButton_clicked();
    void on_browseButton_clicked();

};

#endif // MAINWINDOW_H
